<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { zzcy, bllz } from "@/http/api";
export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tagArr: [
        { label: "全部", value: "" },
        { label: "企业代管", value: "1" },
        { label: "船东自管", value: "2" },
        { label: "企业自管", value: "3" },
      ],
      tableData: [],

      queryData: {
        qy_real_name: "",
        qy_enterprise_name: "",
        qy_staff_name: "",
        cy_sign_number: "",
        qy_glms: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    detailFn(row) {
      this.$router.push({
        path: "/bootSignDetail",
        query: { id: row.cy_sign_id, page: this.queryData.page },
      });
    },
    leaveFn(row) {
      ElMessageBox.prompt(
        "确定为此船员办理离职申请吗?请输入离职原因",
        "操作提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then((value) => {
        let data = {
          cy_sign_id: row.cy_sign_id,
          lz_reason: value.value,
        };
        bllz(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    async getData() {
      const { data } = await zzcy(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>在职船员（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.qy_real_name"
                placeholder="请输入船员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.qy_enterprise_name"
                placeholder="请输入船东公司"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.qy_staff_name"
                placeholder="请输入员工姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.cy_sign_number"
                placeholder="请输入签约单号"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.qy_glms"
                clearable
                @change="getData"
                placeholder="请选择管理模式"
              >
                <el-option
                  v-for="item in tagArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="cy_sign_number"
          width="160"
          show-overflow-tooltip
          label="签约单号"
        />
        <el-table-column
          prop="qy_enterprise_name"
          show-overflow-tooltip
          width="200"
          label="船东公司"
        >
          <template #default="{ row }">
            {{ row.qy_enterprise_name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="qy_real_name"
          show-overflow-tooltip
          label="船员姓名"
        />
        <el-table-column prop="SBType" label="管理模式">
          <template #default="{ row }">
            <el-tag v-if="row.qy_glms == 1">企业代管</el-tag>
            <el-tag type="info" v-if="row.qy_glms == 2">船东自管</el-tag>
            <el-tag type="warning" v-if="row.qy_glms == 3">企业自管</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="qy_cyxz" show-overflow-tooltip label="船员薪资">
          <template #default="{ row }">
            <span>{{ row.qy_cyxz_dw == 1 ? "¥" : "$" }}{{ row.qy_cyxz }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="qy_position_name"
          show-overflow-tooltip
          label="签约岗位"
        >
          <template #default="{ row }">
            {{ row.qy_position_name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="authBook"
          width="140"
          show-overflow-tooltip
          label="证书状况"
        >
          <template #default="{ row }">
            <el-tag
              type="success"
              v-if="row.jjdaoqi_zs.length == 0 && row.daoqi_zs.length == 0"
              >正常</el-tag
            >
            <el-tag
              type="warning"
              v-if="row.jjdaoqi_zs.length > 0 && row.daoqi_zs.length == 0"
              >即将到期({{ row.jjdaoqi_zs.length }}个)</el-tag
            >
            <el-tag type="danger" v-if="row.daoqi_zs.length > 0"
              >已到期({{ row.daoqi_zs.length }}个)</el-tag
            >
          </template>
        </el-table-column>

        <el-table-column prop="SBType" label="任职状态">
          <template #default="{ row }">
            <el-tag type="success" v-if="row.lz_sh_status == 0">在职</el-tag>
            <el-tag v-if="row.lz_sh_status == 1">离职中</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="qy_staff_name"
          show-overflow-tooltip
          label="操作员工"
        >
          <template #default="{ row }">
            {{ row.qy_staff_name }}
          </template>
        </el-table-column>
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="greenText ctrlText" @click="detailFn(row)">详情</div>
              <div
                class="redText ctrlText"
                @click="leaveFn(row)"
                v-if="
                  row.is_auth == 1 &&
                  (row.lz_sh_status == 0 || row.lz_sh_status == 3)
                "
              >
                办理离职
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
